package ${projectDefinitionDO.serverProjectDefinitionDO.serverProjectStartClassPackagePathName}.controller;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.web.base.domain.ResultDO;
import org.web.base.domain.ViewResultHelper;
import org.web.base.domain.helper.ServiceExceptionHelper;
import org.web.base.domain.helper.ValidationHelper;
import org.web.base.domain.view.ViewResultDTO;
import ${projectDefinitionDO.basePackage}.sdk.biz.AccountInfoBiz;
import ${projectDefinitionDO.basePackage}.sdk.dto.AccountInfoDTO;
import ${projectDefinitionDO.basePackage}.sdk.dto.query.QueryAccountInfoRequest;
import ${projectDefinitionDO.serverProjectDefinitionDO.serverProjectStartClassPackagePathName}.domain.AccountInfoDO;
import ${projectDefinitionDO.serverProjectDefinitionDO.serverProjectStartClassPackagePathName}.domain.query.QueryAccountInfo;
import ${projectDefinitionDO.serverProjectDefinitionDO.serverProjectStartClassPackagePathName}.service.AccountInfoService;

<#if projectDefinitionDO.parentProjectDefinitionDO.javaVersion != '1.8' && projectDefinitionDO.parentProjectDefinitionDO.javaVersion != '8'>
import jakarta.annotation.Resource;
<#else>
import javax.annotation.Resource;
</#if>
import java.util.List;


@RequestMapping("${projectDefinitionDO.serverProjectDefinitionDO.serverProjectClassNameForVariableName}AccountInfo")
@Controller("accountInfo")
public class AccountInfoController {

    private static final Logger logger = LogManager.getLogger(AccountInfoController.class);

    @Resource
    private AccountInfoService accountInfoService;

    @Resource
    private AccountInfoBiz accountInfoBiz;

    @RequestMapping("selectAccountInfoList")
    @ResponseBody
    public ViewResultDTO<List<AccountInfoDTO>> selectAccountInfoList(QueryAccountInfoRequest queryAccountInfoRequest) {
        ViewResultDTO<List<AccountInfoDTO>> viewResultDO = new ViewResultDTO<List<AccountInfoDTO>>();
        try {
            // 查询对象校验, 如果调用BIZ层方法，则无需校验，因为BIZ自会进行校验。
            ValidationHelper.validateWithThrow(QueryAccountInfoRequest.class, queryAccountInfoRequest);
            ResultDO<List<AccountInfoDTO>> selectResult = accountInfoBiz.selectAccountInfoList(queryAccountInfoRequest);
            viewResultDO.setData(selectResult.getDomain());
        } catch (Exception e) {
            logger.error(ServiceExceptionHelper.getExceptionInfo(e));
            viewResultDO = ViewResultHelper.buildViewResultByServiceException(e, null);
        }
        return viewResultDO;
    }

    @RequestMapping("selectAccountInfoByAccountInfoId")
    @ResponseBody
    public ViewResultDTO<AccountInfoDTO>  selectAccountInfoByAccountInfoId(Integer accountInfoId) {
        ViewResultDTO<AccountInfoDTO> viewResultDO = new ViewResultDTO<AccountInfoDTO>();
        try {
            AccountInfoDO accountInfoDO = accountInfoService.selectAccountInfoByAccountInfoId(accountInfoId);
            AccountInfoDTO AccountInfoDTO = new AccountInfoDTO();
            BeanUtils.copyProperties(accountInfoDO, AccountInfoDTO);
            viewResultDO.setData(AccountInfoDTO);
        } catch (Exception e) {
            logger.error(ServiceExceptionHelper.getExceptionInfo(e));
            viewResultDO = ViewResultHelper.buildViewResultByServiceException(e, null);
        }
        return viewResultDO;
    }

}

